package org.zcl.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhuchenglin
 * @since 2022/9/7 14:07
 */
public class ResponseUtils {
    private static final Logger log = LoggerFactory.getLogger(ResponseUtils.class);

    public ResponseUtils() {
    }

    public static void writeJson(HttpServletResponse response, String resultJson) {
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        try {
            response.getWriter().write(resultJson);
            response.getWriter().flush();
        } catch (IOException var3) {
            log.error(var3.getMessage(), var3);
        }

    }

    public static void setNoCache(HttpServletResponse response) {
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0L);
    }
}
